package com.trkj.service;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.trkj.dao.jpa.IjliccardDAO;
import com.trkj.pojos.JlIccard;


@Service
@Transactional
public class JlIccardService {
	@Autowired
	private IjliccardDAO IcCardDAO;
	/*
	 * 查看IC卡信息
	 */
	public Map<String, Object> queryStusByPage(int page, int rows){
		PageRequest pr = new PageRequest(page - 1, rows);
		//获取当前页的记录
		List<JlIccard> list = IcCardDAO.findStuByPage(pr);
		//获取总的记录条数
		long total = IcCardDAO.count();
		
		Map<String, Object> map = new HashMap<>();
		map.put("total", total);
		map.put("rows", list);
		return map;
	}
	public Map<String, Object> queryicTopage(int page, int rows,BigDecimal chid){
		long c=chid.longValue();
		//获取当前页的记录
		PageRequest pr = new PageRequest(page - 1, rows);
		//获取当前页的记录
		List<JlIccard> list = IcCardDAO.queryicTopage(pr,c);
		//获取总的记录条数
		long total = IcCardDAO.count();
		
		Map<String, Object> map = new HashMap<>();
		map.put("total", total);
		map.put("rows", list);
		return map;	
		
	}
	
	public Long findMaxStuByPage(){	
		return IcCardDAO.findMaxStuByPage();
	 }	

	public void addIcCard(JlIccard s){
			IcCardDAO.save(s);
		     }
	
	//批量删除学生
		public void delStu(Long[] iId){
			for(int i=0;i<iId.length;i++){
				IcCardDAO.delete(iId[i]);
			}
			
		}
		//根据性别查找
		public List<JlIccard> findbySex(String sex){
			List<JlIccard> list=IcCardDAO.findBySex(sex);
			return list;
		}  
		//根据名字查找
	    public List<JlIccard> findbyname(String sex){
			List<JlIccard> list=IcCardDAO.findbyname(sex);
			return list;
		}
		//根据地址查找
		public List<JlIccard> findbyaddres(String sex){
			List<JlIccard> list=IcCardDAO.findbyaddres(sex);
			return list;
		}
		//根据身份证查找
		public List<JlIccard> findbyiccar(String sex){
			List<JlIccard> list=IcCardDAO.findbyiccar(sex);
			return list;
		}
		public List<JlIccard> findbyregic(long reginid){
			List<JlIccard> list=IcCardDAO.findbyregic(reginid);
			return list;
		}
		public Long findbyid(String reginid){
			Long list=IcCardDAO.findbyid(reginid);
			return list;
		}
		public String findbyname(Long iId){
			return  IcCardDAO.findbyname(iId);			
		}
		public Long nametoic(String name){
			return  IcCardDAO.nametoic(name);			
		}
		public Long iccardtoic(String iIdentityCard){
			return  IcCardDAO.iccardtoic(iIdentityCard);			
		}
		public JlIccard  icnumtoic(Long icnum){
			JlIccard list=IcCardDAO.findOne(icnum);			
			return list;
		}
		
}
